package com.hu.common.util.excel;

import cn.hutool.core.collection.ListUtil;
import com.hu.common.util.excel.dto.PersonDTO;
import com.hu.common.util.excel.dto.PositionDTO;
import com.hu.common.util.excel.kit.ExcelSheetData;
import com.hu.common.util.serializer.JobLogState;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author qiangt
 * @version 1.0
 * @date 2024/12/21 19:37
 * @description: TODO
 */
public class ExcelExporterTest {
    public static void main(String[] args) {
        ExcelSheetData<PersonDTO> personDTOExcelSheetData = new ExcelSheetData<>();
        personDTOExcelSheetData.setSheetDefinition(PersonDTO.class);
        personDTOExcelSheetData.setData(getPersonList());
        ExcelSheetData<PositionDTO> positionDTOExcelSheetData = new ExcelSheetData<>();
        positionDTOExcelSheetData.setSheetDefinition(PositionDTO.class);
        positionDTOExcelSheetData.setData(getPositionList());
        List<ExcelSheetData> excelSheetDataList = ListUtil.of(personDTOExcelSheetData, positionDTOExcelSheetData);

        ExcelExporter excelExporter = new ExcelExporter();
        excelExporter.exportData(excelSheetDataList, "D:\\test.xlsx");
    }

    public static List<PersonDTO> getPersonList() {
        PersonDTO person1 = new PersonDTO();
        person1.setName("张三");
        person1.setAge(18);
        person1.setAddress("北京北京北京北京北京北京北京北京北京北京北京北京北京北京北京北京北京北京北京北京");
        person1.setStaffCode("001");
        person1.setType("A");
        person1.setBirthday(new Date());
        person1.setJoinDay(new Date());
        person1.setCreateTime(LocalDate.of(2024, 12, 21));
        person1.setUpdateTime(LocalDateTime.of(2024, 12, 21, 12, 30));
        person1.setJobLogState(JobLogState.Running);

        PersonDTO person2 = new PersonDTO();
        person2.setName("李四");
        person2.setAge(19);
        person2.setAddress("上海上海上海上海上海上海上海上海上海上海上海");
        person2.setStaffCode("002");
        person2.setBirthday(new Date());
        person2.setJoinDay(new Date());
        person2.setCreateTime(LocalDate.of(2024, 12, 21));
        person2.setUpdateTime(LocalDateTime.of(2024, 12, 21, 12, 30));
        person2.setJobLogState(JobLogState.Running);

        return ListUtil.of(person1, person2);
    }

    public static List<PositionDTO> getPositionList() {
        PositionDTO position1 = new PositionDTO();
        position1.setName("开发工程师开发工程师开发工程师");
        position1.setStaffCode("001");
        PositionDTO position2 = new PositionDTO();
        position2.setName("测试工程师");
        position2.setStaffCode("002");
        return ListUtil.of(position1, position2);
    }
}
